package com.cat.math;

/**
 *   @description https://leetcode.cn/problems/split-array-by-prime-indices/description/
 *   @author 曲大人的喵
 *   @create 2025/10/15 20:55
 *   @since JDK17
 */

public class Solution07 {
    static int N = ((int) (1e5 + 10));
    static boolean[] isPrime = new boolean[N];
    static {
        isPrime[0] = isPrime[1] = true;
        for (int i = 2; i < N; i++) {
            if (!isPrime[i]) {  // 是一个质数
                for (long j = (long) i * i; j < N; j += i) {
                    isPrime[(int) j] = true;
                }
            }
        }
    }
    public long splitArray(int[] nums) {
        long s1 = 0, s2 = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (isPrime[i]) { //
                s1 += nums[i];
            } else {
                s2 += nums[i];
            }
        }

        return Math.abs(s1 - s2);
    }
}
